package com.wolfsea.rvitemdecorationdemo.rvadapter
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.wolfsea.rvitemdecorationdemo.databinding.HomeRvItemBinding

/**
 *@desc  HomeAdapter
 *@author liuliheng
 *@time 2022/3/16  11:16
 **/
class HomeRvAdapter : RecyclerView.Adapter<HomeRvAdapter.HomeViewHolder>() {

    private lateinit var dataSet:MutableList<String>

    private lateinit var binding: HomeRvItemBinding

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeViewHolder {
        binding = HomeRvItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return HomeViewHolder(binding)
    }

    override fun onBindViewHolder(holder: HomeViewHolder, position: Int) {
        binding.homeTvName.text = dataSet[position]
    }

    override fun getItemCount(): Int = this.dataSet.size

    fun setDataSet(dataSet: MutableList<String>?) {
        dataSet?.let {
            this.dataSet = dataSet
            notifyItemRangeChanged(0, this.dataSet.size)
        }
    }

    class HomeViewHolder(binding: ViewBinding) : RecyclerView.ViewHolder(binding.root)
}